package com.gewu.pm.ui.adapter.order;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.gewu.pm.R;
import com.gewu.pm.app.AppAdapter;
import com.gewu.pm.bean.OrderSummaryBean;

/**
 * 订单汇总报表列表适配器
 */
public class OrderSummaryAdapter extends AppAdapter<OrderSummaryBean> {

    public OrderSummaryAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ItemViewHolder();
    }

    private final class ItemViewHolder extends AppAdapter<?>.ViewHolder {

        private final TextView mTitleView;
        private final TextView mProductCodeView;
        private final TextView mProductSpecView;
        private final TextView mDeliveryQuantityView;
        private final TextView mDeliveryAmountView;

        private ItemViewHolder() {
            super(R.layout.order_summary_item);
            mTitleView = findViewById(R.id.tv_title);
            mProductCodeView = findViewById(R.id.tv_product_code);
            mProductSpecView = findViewById(R.id.tv_product_spec);
            mDeliveryQuantityView = findViewById(R.id.tv_delivery_quantity);
            mDeliveryAmountView = findViewById(R.id.tv_delivery_amount);
        }

        @Override
        public void onBindView(int position) {
            OrderSummaryBean item = getItem(position);
            
            // 设置标题
            mTitleView.setText(item.getTitle());
            
            // 固定写死的内容
            mProductCodeView.setText("1000013332");
            mProductSpecView.setText("每箱20包");
            
            // 设置发货数量
            mDeliveryQuantityView.setText(item.getDeliveryQuantity() + "包");
            
            // 设置发货金额
            mDeliveryAmountView.setText(String.format("¥%.2f", item.getPrice()));
        }
    }
}
